package com.collabscm.md.base.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityResult;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.SqlResultSetMappings;
import javax.persistence.Table;

import com.collabscm.pf.model.DomainObject;

/**
 * 系统内机构实体
 * 
 * @author Zeng Raoxing
 */
@Entity
@Table(name = "t_md_organ")

@NamedQueries({
	@NamedQuery(name=Organ.COUNT_ALL_ORGAN, query="select count(*) from Organ where Status = :status"),
	@NamedQuery(name=Organ.MAX_ID, query="select MAX(t.organId) from Organ t"),
})

@NamedNativeQueries ({
	//查询系统定义的常量值
	@NamedNativeQuery(name=Organ.GET_ALL_ORGAN, 
			query="select * from t_md_organ where Status = :status" ,
			resultSetMapping="allOrganMapping")
//	@NamedNativeQuery(name=Organ.COUNT_ALL_ORGAN, 
//			query="select count(*) from t_md_organ where Status = ")
})

//系统常量返回后的映射
@SqlResultSetMappings ({
	@SqlResultSetMapping (
		name="allOrganMapping",
		entities={
			@EntityResult(
				entityClass=Organ.class 
			)
		}
	)
})
public class Organ extends DomainObject {
	
	private static final long serialVersionUID = 1L;
	/** ID */
    private Long organId;
    /** 组织英文名称 */
    private String organEnName;
    /** 英文名缩写 */
    private String organEnAbbr;
    /** 组织中文名称 */
    private String organCnName;
    /** 中文名缩写 */
    private String organCnAbbr;
    /** 国籍 */
    private Long nationality;
    /** 省 */
    private Long province;
    /** 市 */
    private Long city;
    /** 县/区 */
    private Long town;
    /** 地址 */
    private String address;
    /** 邮编 */
    private String postcode;
    /** 营业执照 */
    private String businessLicence;
    /** 组织类型 */
    private Long organCategory;
    /** 组织描述 */
    private String organDesc;
    /** 人民币开户行 */
    private Long bank;
    /** 人民币银行账号 */
    private String bankAccount;
    /** 父机构ID */
    private Long parentOrganId;
    /** 网站地址 */
    private String webAddr;
    
    private Set<Person> persons = new HashSet<Person>(0);
    
    /**
     * 取出所有组织
     */
    public static final String GET_ALL_ORGAN = "getAllOrgan";
    
    /**
     * 取出所有组织总数
     */
    public static final String COUNT_ALL_ORGAN = "countOrgan";
    
    /**
     * 取出最大Id
     */
    public static final String MAX_ID = "maxId";
    
    

	// Property accessors
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name = "Organ_ID", unique = true, nullable = false, precision = 12, scale = 0)
	public Long getOrganId() {
		return this.organId;
	}

	public void setOrganId(Long organId) {
		this.organId = organId;
	}
	
    @Column(name="Organ_EN_Name", nullable=false, length=180)
    public String getOrganEnName() {
        return this.organEnName;
    }
    
    public void setOrganEnName(String organEnName) {
        this.organEnName = organEnName;
    }
    
    @Column(name="Organ_CN_Name", length=180)
    public String getOrganCnName() {
        return this.organCnName;
    }
    
    public void setOrganCnName(String organCnName) {
        this.organCnName = organCnName;
    }
    
    @Column(name="Organ_Category", precision=8, scale=0)
    public Long getOrganCategory() {
        return this.organCategory;
    }
    
    public void setOrganCategory(Long organCategory) {
        this.organCategory = organCategory;
    }
    
    @Column(name="Organ_Desc", length=500)
    public String getOrganDesc() {
        return this.organDesc;
    }
    
    public void setOrganDesc(String organDesc) {
        this.organDesc = organDesc;
    }
    
    @Column(name="Parent_Organ_ID", precision=12, scale=0)
    public Long getParentOrganId() {
        return this.parentOrganId;
    }
    
    public void setParentOrganId(Long parentOrganId) {
        this.parentOrganId = parentOrganId;
    }
    
    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="organ")
    public Set<Person> getPersons() {
        return this.persons;
    }
    
    public void setPersons(Set<Person> persons) {
        this.persons = persons;
    }

    @Column(name="Organ_EN_Abbr", length=30)
	public String getOrganEnAbbr() {
		return organEnAbbr;
	}

	public void setOrganEnAbbr(String organEnAbbr) {
		this.organEnAbbr = organEnAbbr;
	}

	@Column(name="Organ_CN_Abbr", length=60)
	public String getOrganCnAbbr() {
		return organCnAbbr;
	}

	public void setOrganCnAbbr(String organCnAbbr) {
		this.organCnAbbr = organCnAbbr;
	}

	@Column(name="Nationality", precision=8, scale=0)
	public Long getNationality() {
		return nationality;
	}

	public void setNationality(Long nationality) {
		this.nationality = nationality;
	}

	@Column(name="Province", precision=8, scale=0)
	public Long getProvince() {
		return province;
	}

	public void setProvince(Long province) {
		this.province = province;
	}

	@Column(name="City", precision=8, scale=0)
	public Long getCity() {
		return city;
	}

	public void setCity(Long city) {
		this.city = city;
	}

	@Column(name="Town", precision=8, scale=0)
	public Long getTown() {
		return town;
	}

	public void setTown(Long town) {
		this.town = town;
	}

	@Column(name="Address", length=180)
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Column(name="Postcode", length=10)
	public String getPostcode() {
		return postcode;
	}

	public void setPostcode(String postcode) {
		this.postcode = postcode;
	}

	@Column(name="Business_Licence", length=30)
	public String getBusinessLicence() {
		return businessLicence;
	}

	public void setBusinessLicence(String businessLicence) {
		this.businessLicence = businessLicence;
	}

	@Column(name="Bank", precision=8, scale=0)
	public Long getBank() {
		return bank;
	}

	public void setBank(Long bank) {
		this.bank = bank;
	}

	@Column(name="Bank_Account", length=30)
	public String getBankAccount() {
		return bankAccount;
	}

	public void setBankAccount(String bankAccount) {
		this.bankAccount = bankAccount;
	}

	@Column(name="Web_Addr", length=60)
	public String getWebAddr() {
		return webAddr;
	}

	public void setWebAddr(String webAddr) {
		this.webAddr = webAddr;
	}

}